package com.wl.mr.sort;


import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class SortBean implements WritableComparable<SortBean> {

    private Long selfDuration;
    private Long thirDuration;
    private Long sumDuration;
    private String id;


    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(selfDuration);
        out.writeLong(thirDuration);
        out.writeLong(sumDuration);
        out.writeUTF(id);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        in.readLong();
        in.readLong();
        in.readLong();
        in.readUTF();
    }

    public SortBean() {
    }

    public SortBean(Long selfDuration, Long thirDuration, String id) {
        this.selfDuration = selfDuration;
        this.thirDuration = thirDuration;
        this.sumDuration = selfDuration + thirDuration;
        this.id = id;
    }

    @Override
    public int compareTo(SortBean o) {
        if(this.sumDuration > o.sumDuration){
            return -1;
        }else if(this.sumDuration < o.sumDuration){
            return 1;
        }else {
            return 0;
        }
    }

    public Long getSelfDuration() {
        return selfDuration;
    }

    public void setSelfDuration(Long selfDuration) {
        this.selfDuration = selfDuration;
    }

    public Long getThirDuration() {
        return thirDuration;
    }

    public void setThirDuration(Long thirDuration) {
        this.thirDuration = thirDuration;
    }

    public Long getSumDuration() {
        return sumDuration;
    }

    public void setSumDuration(Long sumDuration) {
        this.sumDuration = sumDuration;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return selfDuration +
                "\t" + thirDuration +
                "\t" + sumDuration +
                "\t" + id ;
    }


}
